<template>
    <sc-table-select
        placeholder="---请选择---"
        ref="tableselect"
        v-model="orgcodevalue"
        style="width: 300px"
        :pageId="pageId"
        :userCode="userCode"
        :purviewType="purviewType"
        :attrList="attrList"
        :valueList="valueList"
        :queryList="queryList"
        :orderList="orderList"
        :table-width="640"
        :multiple="multiple"
        :queryType="queryType"
        selectType="org"
        collapse-tags
        collapse-tags-tooltip
        :props="props"
        :selectKeyValue="selectKeyValue"
        @change="change"
        @remove-tag="removeTag"
    >
        <!-- collapse-tags
        collapse-tags-tooltip-->
        <template #header="{}">
            <el-form :inline="true">
                <el-row :gutter="5">
                    <el-col :span="5">
                        <el-input v-model="queryList.materialCode" placeholder="请输入物料编码" style="width: 125px"></el-input>
                    </el-col>
                    <el-col :span="5">
                        <el-input v-model="queryList.materialName" placeholder="请输入物料名称" style="width: 125px"></el-input>
                    </el-col>
                   
                    <el-col :span="4">
                        <el-button type="primary" @click="$refs.tableselect.getData()">查询</el-button>
                    </el-col>
                </el-row>
            </el-form>
        </template>
        <el-table-column prop="applyOrderTime" label="要货日期" width="170"></el-table-column>
        <el-table-column prop="applyOrderCode" label="要货单号" width="150"></el-table-column>
        <el-table-column prop="materialCode" label="物料编码" width="120"></el-table-column>
        <el-table-column prop="materialName" label="物料名称" width="200"></el-table-column>
        <el-table-column prop="taskOrderCode" label="收货单号" width="150"></el-table-column>
        <el-table-column prop="taskOrderTime" label="收货日期" width="170"></el-table-column>
    </sc-table-select>
</template>

<script>
import tool from "@/utils/tool";
import bus from "@/utils/mitt";
export default {
    name: "orgselect",
    props: {
        pageId: { type: String, default: "" },
        multiple: { type: Boolean, default: true },
        userCode: { type: String, default: "super" },
        purviewType: { type: String, default: "super" },
        selectKeyValue: { type: String, default: "Code" },
        defaultQueryList: { type: Object, default: {} }
    },
    data() {
        return {
            queryType: "task-order/sc-item-pages",
            hideClearBtn: true,
            attrList: {},
            valueList: {},
            queryList: {},
            //apiObj: this.$API.demo.page,
            params: {
                name: "demoName",
            },
            orgcodevalue: [],
            props: {
               
            },
            lastOrgVal: [],
        };
    },
    watch: {
        defaultQueryList: {
            handler(newVal,oldVal) { 
                console.log("要货选择查询值变化",newVal);
                // 如果 defaultQueryList 更新了，也更新 queryList
                this.queryList = { ...this.defaultQueryList,...newVal }; 
                this.$refs.tableselect.getData();
            },
        }
    },
    created() {
        // 将 defaultQueryList 的值赋给 queryList
        this.queryList = { ...this.defaultQueryList };
    },
    computed: {},
    
    methods: {
        //值变化
        change(val) {
            console.log("PageId",this.pageId);
            if (Array.isArray(val)) {
                if (val.length == 0) {
                    this.$emit("fatherMethod", []);
                } else {
                    this.$emit("fatherMethod", val,this.pageId);
                }
            } else {
                if (val) {
                    this.$emit("fatherMethod", val,this.pageId);
                }
            }
        },
        async opBindData() {
            console.log("defaultQueryList",this.defaultQueryList);
            this.queryList = { ...this.queryList,...this.defaultQueryList };
            this.$nextTick(() => {
                this.$refs.tableselect.getData();
            });
        },
    },
    async mounted() {
        await this.opBindData();
    },
};
</script>

<style>
.custom-org-el-select-close .el-tag__close {
    display: none !important;
}
</style>
